/*
 * @lc app=leetcode.cn id=506 lang=javascript
 *
 * [506] 相对名次
 */

// @lc code=start
/**
 * @param {number[]} score
 * @return {string[]}
 */
var findRelativeRanks = function(score) {
  const WINNER = ["Gold Medal","Silver Medal","Bronze Medal"];
  const newArr = score.map((item, index) => ({item, index}));
  newArr.sort((a, b) => b.item - a.item);

  const res = new Array(score.length).fill(0);
  for (let i = 0; i < newArr.length;i ++) {
    if (i < 3) {
      res[newArr[i].index] = WINNER[i];
    } else {
      res[newArr[i].index] = (i + 1) + '';
    }
  }
  return res;
};
// @lc code=end

